/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "ORDER_ITEM")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "OrderItem.findAll", query = "SELECT o FROM OrderItem o"),
    @NamedQuery(name = "OrderItem.findByIdOrderItem", query = "SELECT o FROM OrderItem o WHERE o.orderItemPK.idOrderItem = :idOrderItem"),
    @NamedQuery(name = "OrderItem.findByIdOrder", query = "SELECT o FROM OrderItem o WHERE o.orderItemPK.idOrder = :idOrder"),
    @NamedQuery(name = "OrderItem.findByIdPersonalInfo", query = "SELECT o FROM OrderItem o WHERE o.orderItemPK.idPersonalInfo = :idPersonalInfo"),
    @NamedQuery(name = "OrderItem.findByIdBranchenterprise", query = "SELECT o FROM OrderItem o WHERE o.orderItemPK.idBranchenterprise = :idBranchenterprise"),
    @NamedQuery(name = "OrderItem.findByIdEnterprise", query = "SELECT o FROM OrderItem o WHERE o.orderItemPK.idEnterprise = :idEnterprise")})
public class OrderItem implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected OrderItemPK orderItemPK;
    @JoinColumns({
        @JoinColumn(name = "ID_ORDER", referencedColumnName = "ID_ORDER", insertable = false, updatable = false),
        @JoinColumn(name = "ID_PERSONAL_INFO", referencedColumnName = "ID_PERSONAL_INFO", insertable = false, updatable = false),
        @JoinColumn(name = "ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE", insertable = false, updatable = false),
        @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private S3r4Order s3r4Order;
    @JoinColumns({
        @JoinColumn(name = "ID_PRODUCT", referencedColumnName = "ID_PRODUCT"),
        @JoinColumn(name = "ID_BRANCHENTERPRISE1", referencedColumnName = "ID_BRANCHENTERPRISE"),
        @JoinColumn(name = "ID_ENTERPRISE1", referencedColumnName = "ID_ENTERPRISE"),
        @JoinColumn(name = "ID_ITEM", referencedColumnName = "ID_ITEM")})
    @OneToOne(optional = false, fetch = FetchType.LAZY)
    private Item item;

    public OrderItem() {
    }

    public OrderItem(OrderItemPK orderItemPK, Item item) {
        this.orderItemPK = orderItemPK;
        this.item=item;
    }

    public OrderItem(BigInteger idOrderItem, BigInteger idOrder, BigInteger idPersonalInfo, BigInteger idBranchenterprise, BigInteger idEnterprise) {
        this.orderItemPK = new OrderItemPK(idOrderItem, idOrder, idPersonalInfo, idBranchenterprise, idEnterprise);
    }

    public OrderItemPK getOrderItemPK() {
        return orderItemPK;
    }

    public void setOrderItemPK(OrderItemPK orderItemPK) {
        this.orderItemPK = orderItemPK;
    }

    public S3r4Order getS3r4Order() {
        return s3r4Order;
    }

    public void setS3r4Order(S3r4Order s3r4Order) {
        this.s3r4Order = s3r4Order;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (orderItemPK != null ? orderItemPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof OrderItem)) {
            return false;
        }
        OrderItem other = (OrderItem) object;
        if ((this.orderItemPK == null && other.orderItemPK != null) || (this.orderItemPK != null && !this.orderItemPK.equals(other.orderItemPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.OrderItem[ orderItemPK=" + orderItemPK + " ]";
    }
    
}
